package com.wiz.netty.handler;

import io.netty.channel.ChannelHandlerContext;

import com.wiz.data.vo.type.MessageType;
import com.wiz.log.NettyInfoRecord;
import com.wiz.netty.NettyXmlParseFactory;
import com.wiz.netty.message.NettyMessageTO;
import com.wiz.netty.service.NettyBusinessThread;
import com.wiz.netty.service.NettyThreadPool;
import com.wiz.web.manager.ServiceManager;

public class BussinessHandler extends AbstractHandlerAdapter {
	
	private ServiceManager serviceManager;
	
	public BussinessHandler(ServiceManager serviceManager, NettyXmlParseFactory wizXmlFactory){
		super();
		this.serviceManager = serviceManager;
		this.wizXmlFactory = wizXmlFactory;
	}
	
	@Override
	public void channelRead(ChannelHandlerContext ctx,Object msg) throws Exception{
		NettyMessageTO.MessageContent message = (NettyMessageTO.MessageContent)msg;
		if(message.getType() == MessageType.DATA.getId()){//代表正常消息报文
			NettyThreadPool.proccess(new NettyBusinessThread(ctx,message,serviceManager,wizXmlFactory));
		}
		ctx.fireChannelRead(msg);
	}
	
	@Override
	public void exceptionCaught(ChannelHandlerContext ctx,Throwable cause){
		NettyInfoRecord.errorRecord(cause.getMessage()+" in LoginHandler");
	}
}

